package Homework.jdbcWork2;

import jdbc.DButil;

import java.sql.*;

/**
 * @author shkstart
 * @creat 2022-05-14:06
 */
public class countSex {
    public static void main(String[] args) {
        Connection con = null;
        PreparedStatement ps = null;
        ResultSet rs = null;
        try {
            con = DButil.getCon();
            ps = con.prepareStatement("select sex,count(stuno) from s_student group by sex");
            rs = ps.executeQuery();
            System.out.println("性别\t人数");
            while (rs.next()) {
                System.out.println(rs.getString("sex") + "\t" + rs.getInt("count(stuno)"));
            }
        } catch (SQLException e) {
            e.printStackTrace();
        } finally {
            DButil.close(rs, ps, con);
        }
    }
}
